using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;

public enum InputDeviceType
{
    Keyboard,
    Gamepad,
}


/// <summary>
/// 自定义 修改的的键位映射基础信息
/// </summary>
[Serializable]
public class ActionData
{
    public string actionName;
    public string actionKey;
}

[CreateAssetMenu(fileName = "Custom", menuName = "Input/CustomActionMapData")]
public class CustomActionMapData: ScriptableObject
{
    [Header("Keyboard")]
    [SerializeField] 
    public ActionsData Keyboard = new ActionsData(InputDeviceType.Keyboard);
        
    [Header("Gamepad")]
    [SerializeField] 
    public ActionsData Gamepad = new ActionsData(InputDeviceType.Gamepad);
    
    [Serializable]
    public class ActionsData
    {
        [SerializeField,ReadOnly] InputDeviceType device;
        [SerializeField,ReadOnly] List<ActionData> actions = new List<ActionData>();

        public ActionsData(InputDeviceType device)
        {
            this.device = device;
        }
    }
}

// 1. 创建 ReadOnly 属性
public class ReadOnlyAttribute : PropertyAttribute { }
// 2. 创建对应的 PropertyDrawer（必须放在 Editor 文件夹下）
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
public class ReadOnlyDrawer : PropertyDrawer
{
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        // 保存原始 GUI 状态
        bool wasEnabled = GUI.enabled;
        
        // 禁用 GUI 控件
        GUI.enabled = false;
        
        // 绘制属性（不可编辑）
        EditorGUI.PropertyField(position, property, label);
        
        // 恢复原始 GUI 状态
        GUI.enabled = wasEnabled;
    }
}
#endif